package org.example.config;

import jakarta.annotation.Resource;
import net.itbaima.robot.event.RobotListener;
import net.itbaima.robot.event.RobotListenerHandler;
import net.itbaima.robot.listener.MessageListener;
import net.itbaima.robot.service.RobotService;
import net.mamoe.mirai.Bot;
import net.mamoe.mirai.BotFactory;
import net.mamoe.mirai.IMirai;
import net.mamoe.mirai.contact.*;
import net.mamoe.mirai.event.events.*;
import net.mamoe.mirai.message.MessageReceipt;
import net.mamoe.mirai.message.data.*;
import net.mamoe.mirai.utils.BotConfiguration;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;

import java.sql.Array;
import java.util.ArrayList;
import java.util.List;

@RobotListener
public class NormalGroupListener extends MessageListener {
    @Autowired
    RobotService service;
    @Autowired
    Bot bot;
    @Resource
    IMirai mirai;
    private List<MessageChain> list=new ArrayList<>();

    @RobotListenerHandler(contactId = {960899275})  //只监听123456789这个群的消息
    public void handleMessage(GroupMessageEvent event) {
        String senderName = event.getSenderName();
        MessageChain message = event.getMessage();
        System.out.println(senderName+"发送："+event.getMessage().contentToString());

        event.getMessage().plus("232332");
        String nick = bot.getNick();
        Group group = bot.getGroup(960899275);
        bot.getGroups().forEach(f->{
            System.out.println(f.getId());
            System.out.println(f.getName());
            if(f.getId()==960899275){
                System.out.println("------------------");
                f.sendMessage("cfgdg");
                service.sendMessageToGroup(960899275 ,"QQ机器人，有没有让按照文档弄过啊，有些问题需要请假一下，有偿！！---没人理我就5秒一次");
            }
        });

        group.sendMessage("32332");
        System.out.println(nick);


       /* MessageChain message = event.getMessage();
        list.add(message);
        if(message.contentToString().equals("撤回")){
            for (int i = 0; i < list.size(); i++) {
                this.recallMessage(list.get(i));
                list.remove(i);
                i--;
            }
            *//*list.forEach(f->{
                this.recallMessage(f);
                list.remove(f);
            });*//*

        }*/

    }
   @RobotListenerHandler(contactId = {960899275})  //只监听123456789这个群的消息
    public void handleMessage4(NudgeEvent event) {
      event.getSubject().sendMessage("eeeee");

    }/*
    @RobotListenerHandler(contactId = {960899275})  //只监听123456789这个群的消息
    public void handleMessage2(MessageRecallEvent event) {
        String nick = event.getAuthor().getNick();
        System.out.println("nick："+nick);
    }*/
    @RobotListenerHandler
    public void handleMessage(FriendMessageEvent event) {
        String senderName = event.getSenderName();
        System.out.println(senderName+"发送："+event.getMessage().contentToString());
        event.getSender().sendMessage("收到！！！！");
    }
}
